
import 'package:erp/Entity/SalesOrder.dart';
import 'package:erp/Store/SalesOrderStore.dart';
import 'package:erp/UI/Components/EmbeddableStatefulWidget.dart';
import 'package:erp/UI/Components/KeyValueView.dart';
import 'package:erp/UI/Components/ListDividerGenerator.dart';
import 'package:erp/UI/Components/LogoScaffold.dart';
import 'package:erp/UI/Pages/SalesPages/SalesDetailsPage.dart';
import 'package:erp/UI/Pages/SalesPages/SalesPage.dart';
import 'package:flutter/material.dart';

class SalesOrderPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return LogoScaffold(
      title: "سىتىش بىتى",
      assetsLogoName: "assets/pictures/cells.png",
      heroName: "SalesHero",
      contentDelegate: SliverChildListDelegate(ListDividerGenerator(SalesOrderStore.orders.map((order) => buildListItem(order)).toList(), Divider()).items),
      floatingActionButton: FloatingActionButton(
        heroTag: "FloatingActionButton",
        child: Icon(Icons.add),
        onPressed: () async {
          await Navigator.of(context).push(MaterialPageRoute(builder: (context) => SalesPage()));
        },
      ),
    );
  }

  Widget buildListItem(SalesOrder order){
    return EmbeddedWidget(
      initEvent: (state){

      },
      widgetBuilder: (context, state){
        return ExpansionTile(
          title: KeyValueView({
            "خىرىدار: ": order.customerName ?? "",
            "بىجىرگۈچى: ": order.employeeName,
            "تالون نومۇرى: ": order.orderNumber
          },),
          leading: Hero(
            tag: order.orderNumber,
            child: Image.asset("assets/pictures/cells.png", height: 40.0, width: 40.0,),
          ),
          children: <Widget>[
            KeyValueView({
              "ۋاقتى: ": order.time,
              "ئومومى سوممىسى: ": order.amount.toString(),
              "ئەمەلىي سوممىسى: ": order.sAmount.toString(),
            },),
            FlatButton(
              child: Text("چىكىپ تەپسىلاتىنى كۆرۈڭ"),
              onPressed: () async {
                await Navigator.of(context).push(MaterialPageRoute(builder: (context) => SalesDetailsPage(order)));
              },
            )
          ],
        );
      }
    );
  }
}

